<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  
      xmlns:ui="http://java.sun.com/jsf/facelets"  
      xmlns:h="http://java.sun.com/jsf/html"  
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">  
      
    <h:body>  
        <ui:composition template="WEB-INF/facelets/template.xhtml">  
            <ui:param name="title" value="View products"/>
            <ui:define name="content">  
                           
           <h:form>                
            <p:dataTable id="products" value="#{viewProductsControllerBean.productList}" var="product">  
  
                <p:column sortBy="#{product.name}">  
                    <f:facet name="header">  
                        <h:outputText value="Name" />  
                    </f:facet>  
                    <h:outputText value="#{product.name}" />  
                </p:column>  
  
                <p:column sortBy="#{product.cat}">  
                    <f:facet name="header">  
                        <h:outputText value="Cat" />  
                    </f:facet>  
                    <h:outputText value="#{product.cat}" />  
                </p:column> 
                
                <p:column sortBy="#{product.price}">  
                    <f:facet name="header">  
                        <h:outputText value="Price"/>  
                    </f:facet>  
                    <h:outputText value="#{product.price}" />  
                </p:column> 
                
                <p:column>  
                    <p:commandButton value="remove" action="#{viewProductsControllerBean.removeProduct}" update="@form">
                        <f:setPropertyActionListener target="#{viewProductsControllerBean.selected}" value="#{product}" />
                    </p:commandButton>
                </p:column> 
                
                <p:column>
                    <p:commandButton value="Add to cart" action="#{shoppingCart.doAdd}" update="@form">
                        <f:setPropertyActionListener target="#{shoppingCart.selected}" value="#{product}"/>
                    </p:commandButton>
                </p:column>
        </p:dataTable><br/>

                    <h:commandButton value="Add Product" action="onViewAddProduct" />
                    <h:commandButton value="View Cart" action="onViewCart" />
                    <h:commandButton value="Empty Cart" action="#{viewProductsControllerBean.doEmpty}" /><br/><br/>
                    You have <h:outputText value="#{shoppingCart.numberOfProducts}"/> items in your shopping cart
                </h:form><br/>
            </ui:define>  
              <br/>
        
        </ui:composition>  
        
    </h:body>  
</html>  
